#!/usr/bin/env python
import sys
import helper
import class_set
from sets import Set

class FollowRecommendationReducer(helper.ReducerHelper):
    def processor(self, key, lst):
        list_type1 = Set()
        list_type2 = Set()
        for e in lst:
            left, right = self.split(e)
            recom_tag = class_set.RecomTag('')
            recom_tag.init(right)
            if recom_tag.isType('1'):
                list_type1.add(left)
            elif recom_tag.isType('2'):
                list_type2.add(left)
            else:
                raise Exception
        recom_tag = class_set.RecomTag('follow')
        recom_tag.setRelatedId(key)
        for el in list_type2:
            for er in list_type1:
                if el != er:
                    self.allocator(self.join(el, er), recom_tag) 
                
def main():
    fr = FollowRecommendationReducer()
    fr.reducer()

if __name__ == '__main__':
    main()

